using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace Scurvy.Media.VideoModel
{
    public class VidReader : ContentTypeReader<Video>
    {
        protected override Video Read(ContentReader input, Video existingInstance)
        {
            if (existingInstance != null)
            {
                existingInstance.Stop();
                
                return existingInstance;
            }

            int framecount = input.ReadInt32();
            double framerate = input.ReadDouble();
            Vector2 size = input.ReadVector2();
            PlaybackType playtype = (PlaybackType)input.ReadInt16();
            bool usecompression = input.ReadBoolean();

            switch (playtype)
            {
                case PlaybackType.InMemory:
                    existingInstance = new VideoInMemory(framecount, framerate);
                    //TODO: read list of textures into vid in mem instance
                    break;
                case PlaybackType.Stream:
                    existingInstance = new VideoStream(input, framecount, framerate, (int)size.Y, (int)size.X, VideoManager._device, usecompression);
                    break;
                default:
                    throw new InvalidVideoContentException(string.Format("PlayType of {0} not supported", playtype));
            }

            return existingInstance;
        }
    }
}
